// ignore_for_file: non_constant_identifier_names

class RevMsgModel {
  String? event;
  String? conversation_id;
  String? message_id;
  int? created_at;
  String? task_id;
  String? id;
  String? answer;
  Metadata? metadata;
  String? code;
  int? status;
  String? message;


  RevMsgModel({
    this.event,
    this.conversation_id,
    this.message_id,
    this.created_at,
    this.task_id,
    this.id,
    this.answer,
    this.metadata,
    this.code,
    this.status,
    this.message,
  });

  Map<String, dynamic> toJson() {
    return {
      "event": event,
      "conversation_id": conversation_id,
      "message_id": message_id,
      "created_at": created_at,
      "task_id": task_id,
      "id": id,
      "answer": answer,
      "metadata": metadata?.toJson(),
      "code": code,
      "status": status,
      "message": message,
    };
  }

  factory RevMsgModel.fromJson(Map<String, dynamic> json) {
    return RevMsgModel(
      event: json["event"],
      conversation_id: json["conversation_id"],
      message_id: json["message_id"],
      created_at: json["created_at"],
      task_id: json["task_id"],
      id: json["id"],
      answer: json["answer"],
      code: json["code"],
      status: json["status"],
      message: json["message"],
      metadata:
          json["metadata"] != null ? Metadata.fromJson(json["metadata"]) : null,
    );
  }

  bool get isEnd {
    return event?.endsWith('_end') ?? true;
  }

  bool get isError {
    return event?.endsWith('error') ?? false;
  }

}


class Metadata {
  Usage? usage;

  Metadata({
    this.usage,
  });

  Map<String, dynamic> toJson() {
    return {
      "usage": usage?.toJson(),
    };
  }

  factory Metadata.fromJson(Map<String, dynamic> json) {
    return Metadata(
      usage: json['usage'] != null ? Usage.fromJson(json["usage"]) : null,
    );
  }

}

class Usage {
  int? prompt_tokens;
  String? prompt_unit_price;
  String? prompt_price_unit;
  String? prompt_price;
  int? completion_tokens;
  String? completion_unit_price;
  String? completion_price_unit;
  String? completion_price;
  int? total_tokens;
  String? total_price;
  String? currency;
  double? latency;

  Usage({
    this.prompt_tokens,
    this.prompt_unit_price,
    this.prompt_price_unit,
    this.prompt_price,
    this.completion_tokens,
    this.completion_unit_price,
    this.completion_price_unit,
    this.completion_price,
    this.total_tokens,
    this.total_price,
    this.currency,
    this.latency,
  });

  Map<String, dynamic> toJson() {
    return {
      "prompt_tokens": prompt_tokens,
      "prompt_unit_price": prompt_unit_price,
      "prompt_price_unit": prompt_price_unit,
      "prompt_price": prompt_price,
      "completion_tokens": completion_tokens,
      "completion_unit_price": completion_unit_price,
      "completion_price_unit": completion_price_unit,
      "completion_price": completion_price,
      "total_tokens": total_tokens,
      "total_price": total_price,
      "currency": currency,
      "latency": latency,
    };
  }

  factory Usage.fromJson(Map<String, dynamic> json) {
    return Usage(
      prompt_tokens: json["prompt_tokens"],
      prompt_unit_price: json["prompt_unit_price"],
      prompt_price_unit: json["prompt_price_unit"],
      prompt_price: json["prompt_price"],
      completion_tokens: json["completion_tokens"],
      completion_unit_price: json["completion_unit_price"],
      completion_price_unit: json["completion_price_unit"],
      completion_price: json["completion_price"],
      total_tokens: json["total_tokens"],
      total_price: json["total_price"],
      currency: json["currency"],
      latency: json["latency"],
    );
  }

}
